package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Skill;
import com.ruoyi.system.service.ISkillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职业技能Controller
 * 
 * @author WEI&WU
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/system/skill")
public class SkillController extends BaseController
{
    @Autowired
    private ISkillService skillService;

    /**
     * 查询职业技能列表
     */
    @PreAuthorize("@ss.hasPermi('system:skill:list')")
    @GetMapping("/list")
    public TableDataInfo list(Skill skill)
    {
        startPage();
        List<Skill> list = skillService.selectSkillList(skill);
        return getDataTable(list);
    }

    /**
     * 导出职业技能列表
     */
    @PreAuthorize("@ss.hasPermi('system:skill:export')")
    @Log(title = "职业技能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Skill skill)
    {
        List<Skill> list = skillService.selectSkillList(skill);
        ExcelUtil<Skill> util = new ExcelUtil<Skill>(Skill.class);
        util.exportExcel(response, list, "职业技能数据");
    }

    /**
     * 获取职业技能详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:skill:query')")
    @GetMapping(value = "/{certificateId}")
    public AjaxResult getInfo(@PathVariable("certificateId") String certificateId)
    {
        return success(skillService.selectSkillByCertificateId(certificateId));
    }

    /**
     * 新增职业技能
     */
    @PreAuthorize("@ss.hasPermi('system:skill:add')")
    @Log(title = "职业技能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Skill skill)
    {
        return toAjax(skillService.insertSkill(skill));
    }

    /**
     * 修改职业技能
     */
    @PreAuthorize("@ss.hasPermi('system:skill:edit')")
    @Log(title = "职业技能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Skill skill)
    {
        return toAjax(skillService.updateSkill(skill));
    }

    /**
     * 删除职业技能
     */
    @PreAuthorize("@ss.hasPermi('system:skill:remove')")
    @Log(title = "职业技能", businessType = BusinessType.DELETE)
	@DeleteMapping("/{certificateIds}")
    public AjaxResult remove(@PathVariable String[] certificateIds)
    {
        return toAjax(skillService.deleteSkillByCertificateIds(certificateIds));
    }
}
